package com.xinzhi.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String EXCHANGE_NAME = "fanout_exchage";
    public static final String QUEUE_NAME = "fanout_queue";

    @Bean("queue")
    public Queue queue(){
//        return new Queue(QUEUE_NAME, true, false, false);
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    @Bean("exchange")
    public Exchange exchange(){
//        return new FanoutExchange(EXCHANGE_NAME, true, false);
        return ExchangeBuilder.fanoutExchange(EXCHANGE_NAME).durable(true).build();
    }


    @Bean
    public Binding binding(@Qualifier("queue") Queue queue, @Qualifier("exchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }


}
